package com.wyp168.gulimall.product.web;

import com.wyp168.gulimall.product.entity.CategoryEntity;
import com.wyp168.gulimall.product.service.CategoryService;
import com.wyp168.gulimall.product.vo.Category2VO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @ClassName IndexController
 * @Title TODO
 * @Description TODO
 * @Author wyp168
 * @Date 2023/8/27 21:24
 */
@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    @RequestMapping(value = {"", "index", "index.html"})
    public String indexPage(Model model) {
        List<CategoryEntity> categoryList = categoryService.getLevelOneCategorys();
        model.addAttribute("categorys", categoryList);
        return "index";
    }

    @ResponseBody
    @GetMapping("getCategoryJson")
    public Map<String, List<Category2VO>> getCategoryJson() {
        Map<String, List<Category2VO>> resultMap= categoryService.getCategoryJson();
        return resultMap;
    }
}
